package com.rasenhund.android.grecorder.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.rasenhund.android.grecorder.R;
import com.rasenhund.android.grecorder.common.Const;
import com.rasenhund.android.grecorder.schema.StageRecord;

public class StageListAdapter extends ArrayAdapter<StageRecord> {
    
    private Context mContext;

    private List<StageRecord> items;
    private LayoutInflater mInflater;
    
    public StageListAdapter(Context context, List<StageRecord> objects) {
        super(context, 0, objects);
        
        mContext = context;

        mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        items = objects;
        
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
//        super.getView(position, convertView, parent);
        
        View view;

        if (convertView != null) {
            view = convertView;
        } else {
            view = mInflater.inflate(R.layout.list_stage_row, null);
        }

        StageRecord item = getItem(position);

        if (item != null) { 
            
            TextView stageId = (TextView) view.findViewById(R.id.stageId);
            stageId.setText(String.valueOf(item.getStageCd()));
            
            TextView stageNm = (TextView) view.findViewById(R.id.stageNm);
            String sStageNm = Const.getStageNm(mContext, item.getStageCd());
            stageNm.setText(sStageNm);
            
            TextView total = (TextView)view.findViewById(R.id.totalCount);
            total.setText(String.valueOf(item.getTotalCount()));
            
            TextView win = (TextView)view.findViewById(R.id.winCount);
            win.setText(String.valueOf(item.getWinCount()));
            
            TextView lose = (TextView)view.findViewById(R.id.loseCount);
            lose.setText(String.valueOf(item.getLoseCount()));
            
            TextView draw = (TextView)view.findViewById(R.id.drawCount);
            draw.setText(String.valueOf(item.getDrawCount()));
            
            TextView perWin = (TextView)view.findViewById(R.id.perWin);
            perWin.setText(String.valueOf(item.getPerWin()));
            
        }

        return view;

    }
    
    @Override
    public StageRecord getItem(int position) {
        return items.get(position);
    }
    
    @Override
    public long getItemId(int position) {
        return items.get(position).getStageCd();
    }
        
}
